Option Explicit
Dim oFS, oDDF, args

Set args = WScript.Arguments

' Create the File System Object
Set oFS = CreateObject("Scripting.FileSystemObject")

Set oDDF = oFS.CreateTextFile(args(0) + "cab.ddf", true)
oDDF.WriteLine ";"
oDDF.WriteLine ".Set CabinetNameTemplate=" + args(1) + ".wsp"
oDDF.WriteLine ".set DiskDirectoryTemplate=CDROM ; All cabinets go in a single directory"
oDDF.WriteLine ".Set CompressionType=MSZIP;** All files are compressed in cabinet files"
oDDF.WriteLine ".Set UniqueFiles='ON'"
oDDF.WriteLine ".Set Cabinet=on"
oDDF.WriteLine ".Set DiskDirectory1=" + args(2)
oDDF.WriteLine ".Set MaxDiskSize=51200000000000000000000000000000000000"

' Add the assembly files
EnumFolder args(0) + "DLLS", ""

' Add the schema files
EnumFolder args(0) + "12", ""

'Add the manifest file
oDDF.WriteLine """" + args(0) +"manifest.xml"+ """" + vbTab + """" + "manifest.xml"""

oDDF.WriteLine ";*** <the end>"

oDDF.Close

Sub EnumFolder(sFolder, sRelativePath)
    
    Dim oFolder, oFolders, oSub, oFile
    Set oFolder = oFS.GetFolder(sFolder)
    
    'Skip DLLS\SafeControls folder
    If (oFolder.Name = "SafeControls" And oFolder.ParentFolder.Name = "DLLS") Then Exit Sub

    'Skip 12\TEMPLATE\SiteTemplates\WEBTEMP folder
    If (oFolder.Name = "WEBTEMP" And oFolder.ParentFolder.Name = "SiteTemplates") Then Exit Sub
            
    If (oFolder.Name = "TEMPLATE" And oFolder.ParentFolder.Name = "12") Then sRelativePath = ""
    If (oFolder.Name = "FEATURES" And oFolder.ParentFolder.Name = "TEMPLATE") Then sRelativePath = ""
    If (oFolder.Name = "SiteTemplates" And oFolder.ParentFolder.Name = "TEMPLATE") Then sRelativePath = ""

    If (sRelativePath <> "") Then sRelativePath = sRelativePath + "\"

    For Each oFile In oFolder.Files
        oDDF.WriteLine """" + oFile.Path + """" + vbTab + """" + sRelativePath + oFile.Name + """"
    Next

    If (sRelativePath <> "" And InStr(1, sFolder, "12\TEMPLATE\FEATURES") > 0) Then
       If (Left(sRelativePath,9) <> "FEATURES\") Then
          sRelativePath = "FEATURES\" + sRelativePath
       End If
    End If

    For Each oSub In oFolder.SubFolders
        EnumFolder oSub.Path, sRelativePath + oSub.Name
    Next
    
End Sub